package com.wisdytech.linkdcs.equipLifeCycle.malfunction.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MProcessRecord;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMProcessRecordService;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.vo.MProcessVo;
import com.wisdytech.linkdcs.system.model.SysUser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dailibo
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/equipLifeCycle/malfunction/process")
public class MProcessRecordController {
	
	private Logger logger =LoggerFactory.getLogger(getClass());
	
	@Autowired
	private IMProcessRecordService iMProcessRecordService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
	
	@RequestMapping("/index")
	public String recoreIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
		return "lifeCycle/equipLifeCycle/malfunction/process";
	}
	
	
	@RequestMapping("/addProcess/add.mvc")
	@ResponseBody
	public StandardResult process(MProcessRecord pReocrd) {
		
		SysUser user =BaseUtil.getCurrentUser();
		
		return  iMProcessRecordService.processRecord(pReocrd, user.getUsername())?
				StandardResult.getSuccessResult():
					StandardResult.getFailResult("保存失败");
	}
	
	
	@RequestMapping("/getProcess/get.mvc")
	@ResponseBody
	public StandardResult getProcessResult(String pkId) {
		
		MProcessVo  vo =
				iMProcessRecordService.getProcessRecord(pkId);
		
		if(null == vo ) {
			return StandardResult.getFailResult();
		}
		
		return StandardResult.getSuccessResult(vo);
	}
	

}

